import urllib.request as req
import urllib.parse as par
import json
url = "https://fanyi.baidu.com/v2transapi?from=en&to=zh"
print(url)
data = {
    "from": "en",
    "to": "zh",
    "query": "love",
    "transtype": "realtime",
    "simple_means_flag": "3",
    "sign": "198772.518981",
    "token": "a439c16b87cf011d6852d31eda131775",
    "domain": "common"
}
header = {
    'Cookie': 'BIDUPSID=2EB6D7D4103CF43086A32CACEE81BBD3; PSTM=1617171638; __yjs_duid=1_ca139bfff2f28e59d537ecd80584ef201619765442822; H_WISE_SIDS=107320_110085_127969_132547_178384_178631_179348_179445_179623_181482_181588_182237_182531_183031_183329_183982_184011_184794_184892_185268_185879_186319_186595_186636_186664_186668_187061_187282_187292_187356_187362_187417_187449_187529_187726_187957_188031_188054_188154_188182_188332_188353_188426_188452_188469_188552_188614_188731_188747_188843_188875_188992_189325_189390_189412_189526_189680_189731_189740_189755_189758_190012_190035_190298_190461_190473_190522_190568_190588_190617_190680_190681_190756_191030_191071_191083_191371_191420_191425_191473_191475_191501_191505_191534_191641_192152; BAIDUID=020EC8036C6AE259FC01FE1B2626A52E:SL=0:NR=10:FG=1; H_WISE_SIDS_BFESS=107320_110085_127969_132547_178384_178631_179348_179445_179623_181482_181588_182237_182531_183031_183329_183982_184011_184794_184892_185268_185879_186319_186595_186636_186664_186668_187061_187282_187292_187356_187362_187417_187449_187529_187726_187957_188031_188054_188154_188182_188332_188353_188426_188452_188469_188552_188614_188731_188747_188843_188875_188992_189325_189390_189412_189526_189680_189731_189740_189755_189758_190012_190035_190298_190461_190473_190522_190568_190588_190617_190680_190681_190756_191030_191071_191083_191371_191420_191425_191473_191475_191501_191505_191534_191641_192152; MCITY=-:; BDUSS=hBczJrLUhpZk5-OEhjfkt4US05LWdiRmtYeW9YaE9qZEhCdXRBckJCd1lQWDlqSVFBQUFBJCQAAAAAAAAAAAEAAABPyAZOsK7R0L6~tcTQ3Lqi19MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABiwV2MYsFdjU3; BDUSS_BFESS=hBczJrLUhpZk5-OEhjfkt4US05LWdiRmtYeW9YaE9qZEhCdXRBckJCd1lQWDlqSVFBQUFBJCQAAAAAAAAAAAEAAABPyAZOsK7R0L6~tcTQ3Lqi19MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABiwV2MYsFdjU3; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; ZFY=21SZ:BXjLPs1LbS:BtbAqfG6FtqsKBsRRssf6t0LKSNwg:C; BAIDUID_BFESS=020EC8036C6AE259FC01FE1B2626A52E:SL=0:NR=10:FG=1; BA_HECTOR=a50h2g048481a525al0gaf9l1hm8uqc1f; ariaDefaultTheme=undefined; H_PS_PSSID=36557_36885_34812_37624_36805_36786_37534_37500_26350_37479_22159; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; delPer=0; PSINO=6; __bid_n=184419d0faf6e5f2014207; RT="z=1&dm=baidu.com&si=qddutv0jfd&ss=la273bmr&sl=6&tt=ckn&bcn=https://fclog.baidu.com/log/weirwood?type=perf&ul=xxyo&hd=xy6w"; APPGUIDE_10_0_2=1; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1667549883; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1667551537; ab_sr=1.0.1_MmRjNzliYzgxMTBmZDgxNWNjMjc5OTdjMDhhMzFlNzcwZGU2NGIzMzU0ZDljZWMyMjFjYjJjMTY1MmNiODdhYTgxMGNjZGFiNjI5NWM3Y2E5NjNlZDI3NWNjMzI5OTQwYmExNGI1YzY2MDNlYmJmYmRhY2ZhYjBiMWMwNzc4Yzg0YzVhODQ3YWY5NDE4NGNhZTc4OTA3NjY4MDI4NGNmZTRjN2VhMmE0MDk4MjE0NmFmYTRlYWE4NTIxM2VjMjk1'
}
data = par.urlencode(data).encode("utf-8")
#print(data)
request = req.Request(url=url, data=data, headers=header)
res = req.urlopen(request)
con = res.read().decode("utf-8")
con = json.loads(con)
#print(con)
